def qbm():
    import tkinter as tk
    bmwindow=tk.Tk()
    bmwindow.title("求补码")
    bmwindow.geometry("650x850")
    def sfhb():
        f=e1.get()
    def szsb():
        s=eval(e2.get())
    def xsqbm():
        f=e1.get()
        s=eval(e2.get())
        s0=s
        sp=[]
        fp=[]
        bp=[]
        co=0
        if f=='+':
            if s==0:
                tx.insert('insert',"\n+{0}计算过程：\n0\n00\n".format(s0))
                tx.insert('insert',"+0补码为：\n")
                tx.insert('insert',"00\n")
            else:
                tx.insert('insert',"\n+{0}计算过程：\n".format(s0))
                while s>0:
                    x=s%2
                    sp.append(x)
                    s=s//2
                    tx.insert('insert',"{0}\n".format(sp))
                sp.reverse()
                sp.insert(0,0)
                tx.insert('insert',"+{0}补码为：\n".format(s0))
                tx.insert('insert',"{0}\n".format(sp))
        if f=='-':
            if s==0:
                tx.insert('insert',"\n-{0}计算过程：\n0\n00\n".format(s0))
                tx.insert('insert',"-0补码为：\n")
                tx.insert('insert',"00\n")
            else:
                while s>0:
                    x=s%2
                    sp.append(x)
                    s=s//2
                sp.reverse()
                sp.insert(0,1)
#            print(sp)
                tx.insert('insert',"\n-{0}计算过程：\n".format(s0))
                for i in sp:
                    if co!=0:
                        if i==0:
                            fp.append(1)
                            tx.insert('insert',"{0}\n".format(fp))
                        elif i==1:
                            fp.append(0)
                            tx.insert('insert',"{0}\n".format(fp))
                    elif co==0:
                        fp.append(i)
                        tx.insert('insert',"{0}\n".format(fp))
                    co=co+1
                    
                tx.insert('insert',"\n-{0}反码为：\n".format(s0))
                tx.insert('insert',"{0}\n".format(fp))

                jw = 0 #进位值初始设定为0，开始对补码做二进制加1操作
                addone = 1 #要加上的1
                if fp[len(fp)-1]+addone == 1:
                    fp[len(fp)-1]=1
                    jw=0
                elif fp[len(fp)-1]+addone == 2:
                    fp[len(fp)-1]=0
                    jw=1
                    for i in range(len(fp)-2,-1,-1):
                        if jw+fp[i] == 1:
                            fp[i]=1
                            jw=0
                            #print(fp)
                            if jw == 0:
                                break;
                        elif jw+fp[i] == 2:
                            fp[i]=0
                            jw=1

                if jw == 1:
                    fp.insert(0,1)
                tx.insert('insert',"\n-{0}补码为：\n".format(s0))
                tx.insert('insert',"{0}\n".format(fp))
                
            tx.insert('insert',' \n')
            
    lb1=tk.Label(bmwindow, text='输入整数的符号（+/-）', bg='orange', font=('Arial', 12), width=30)
    lb1.pack()
    e1 = tk.Entry(bmwindow,font=('Arial', 14))
    e1.pack()
    bt1=tk.Button(bmwindow,text='确认符号',width=10,font=('Arial', 12),command=sfhb)
    bt1.pack()
    
    lb2=tk.Label(bmwindow, text='输入整数（不带符号）', bg='orange', font=('Arial', 12), width=30)
    lb2.pack()
    e2 = tk.Entry(bmwindow,font=('Arial', 14))
    e2.pack()
    bt2=tk.Button(bmwindow,text='确认数字',width=10,font=('Arial', 12),command=szsb)
    bt2.pack()
    
    lb3=tk.Label(bmwindow, text='---------------------------------------------', bg='orange', font=('Arial', 12), width=30)
    lb3.pack()
    bt3=tk.Button(bmwindow,text='求解补码',width=10,font=('Arial', 12),command=xsqbm)
    bt3.pack()
    
    lb4=tk.Label(bmwindow, text='结果与过程如下：', bg='orange', font=('Arial', 12), width=30)
    lb4.pack()
    tx=tk.Text(bmwindow,width=85,height=40)
    tx.pack()
    bmwindow.mainloop()